﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.Win32;


namespace BadassPhotoAlbum
{
    static class Program
    {
        /// <summary>
        /// Created by: Ryan and Ethan then edited by Adam and Mike
        /// The main entry point for the application.
        /// Obtained help for creating the mutex object from http://www.ai.uga.edu/mc/SingleInstance.html
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool oneInstance;

            //do a .net check
           // help from http://stackoverflow.com/questions/198931/how-do-i-tell-if-net-3-5-sp1-is-installed
            const string name = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5";
            RegistryKey subKey = Registry.LocalMachine.OpenSubKey(name);
            var version = subKey.GetValue("Version").ToString();
            var servicePack = subKey.GetValue("SP").ToString();

            if (servicePack.ToString() != "1")
            {
                MessageBox.Show("Microsoft .NET 3.5 Service pack 1 not installed");
                return;
            }

            Object myMutexObject = new System.Threading.Mutex(true, "theMutex", out oneInstance); //holds object that checks if program is already open
            if (!oneInstance)
            {
                bool doubleInstanceCheck;
                Object doubleTex = new System.Threading.Mutex(true, "theMutex2", out doubleInstanceCheck); //holds object that checks if program is already open
                if (!doubleInstanceCheck)
                    return;
                MessageBox.Show("Another instance of the program is already running."); //this will only be shown once.
                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new MainForm()); //old form
            Application.Run(new ControlForm());
            
            GC.KeepAlive(myMutexObject);//prevents the mutex object from being permaturely released.
        }
    }
}
